home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / win_fs < prev    next >
Encoding:
Text File  |  1989-10-17  |  68.1 KB  |  2,094 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Agfa Compugraphic Division
  3. subject: v08i094: PD MS-DOS C windowing system
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: fredex@cg-atla.UUCP (Fred Smith)
  6.  
  7. Posting-number: Volume 8, Issue 94
  8. Submitted-by: fredex@cg-atla.UUCP (Fred Smith)
  9. Archive-name: win_fs
  10.  
  11. Below is a shar of a public domain C language windowing package for MS-DOS
  12. systems. It is said to be compatible with both Microsoft C V 4.00 and later
  13. and also with Turbo C.
  14.  
  15. PLEASE NOTE that I did not write this and am not supporting it--I am merely
  16. posting it for your edification. The name and address of the author are
  17. given in the documentation. All comments should go to him and not me.
  18.  
  19. Enjoy!
  20.  
  21. Fred
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of shell archive."
  30. # Contents:  win.doc win.c win.h scrio.c windemo.c
  31. # Wrapped by fredex@cg-atla on Tue Oct 17 12:58:30 1989
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'win.doc' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'win.doc'\"
  35. else
  36. echo shar: Extracting \"'win.doc'\" \(11554 characters\)
  37. sed "s/^X//" >'win.doc' <<'END_OF_FILE'
  38. X
  39. X
  40. X         C-WIN - A Public Domain 'C' Windowing System
  41. X         --------------------------------------------
  42. X
  43. X                 Introduction
  44. X                 ============
  45. X
  46. X   This package was developed as a result of my desire to have a windowing
  47. X   system written in a portable language.  In the three years I've been
  48. X   using the 'C' language I've progressed through six compilers.  Each time
  49. X   I've had to make extensive modifications to assembly language
  50. X   subroutines to adapt them to the new compiler environment.  In addition,
  51. X   I've occasionally used commercial libraries of functions for which I've
  52. X   only had executable code.  These libraries, of course, did not work with
  53. X   the new compiler and I was faced with a choice of purchasing a new
  54. X   version of the library or writing my own functions to replace the
  55. X   library routines I was using.  After encountering this agony several
  56. X   times I've come up with a simple solution.  If I don't have the source
  57. X   code to a function, it does not get linked into any of my programs!
  58. X
  59. X   I'm well aware that there are many commercial windowing packages
  60. X   available and some are even willing to give you the source code.  These
  61. X   packages must be outstanding because they sure cost a lot.
  62. X   Nevertheless, here is my first effort at a 'C' windowing package.
  63. X   Humble as it may be the cost is right on.  It is free and you can have
  64. X   the source code.  I don't want to sell it to you and I don't want you to
  65. X   make a contribution if you like it.    It is 100% public domain software,
  66. X   do with it as you please.
  67. X
  68. X                 Compilers Supported
  69. X                 ===================
  70. X
  71. X   This software has been developed using both Borland Turbo C V1.0 and
  72. X   Microsoft C V5.00.  I've also tested the code using Microsoft C V4.00.
  73. X   I've tried to write this code in a portable manner and it should compile
  74. X   with little or no change on most of the newer compilers which are
  75. X   following the ANSI standard.  I have used the Microsoft extension
  76. X   keywords "pascal" and "near" to generate more efficient code but, if
  77. X   your compiler doesn't support them, they can be removed without harming
  78. X   anything.
  79. X
  80. X                    Files
  81. X                    =====
  82. X
  83. The package consists of a single header and two source code files:
  84. X
  85. X      WIN.H        The header file for use by the application code
  86. X            as well as the windowing library code.
  87. X
  88. X      WIN.C        The high level windowing functions. All code in
  89. X            this file is machine independent.
  90. X
  91. X      SCRIO.C        The low level screen access routines.  This code
  92. X            is machine dependent and is written for the IBM/PC
  93. X            and true compatibles.
  94. X
  95. X      WINDEMO.C     A short demo program which shows some of the
  96. X            windowing functions in action.
  97. X
  98. X                   Video Equipment
  99. X                   ===============
  100. X
  101. X   This code will work properly on both TTL Monchrome and IBM CGA video
  102. X   boards.  In addition, it should work fine on both EGA and VGA boards.
  103. X   Following are some comments related to these video cards:
  104. X
  105. X     -    Monochrome:    The ScrInitialize function will detect a monochrome
  106. X               mode and automatically convert all attribute bytes
  107. X               to black and white.  This is done in a manner that
  108. X               I find to be reasonable, if you disagree change the
  109. X               code that does the conversion.
  110. X
  111. X     -    CGA:           Due to the snow generated by most CGA cards if the
  112. X               video buffer is accessed during video refresh this
  113. X               code disables the video signal while directly
  114. X               updating the video buffer.
  115. X
  116. X     -    EGA:           Currently EGA color modes are treated as CGA.  Most
  117. X               schemes I've seen to detect an EGA search the EGA
  118. X               extended BIOS for the IBM copyright notice.  This,
  119. X               to me, is not a good approach.  I have seen one
  120. X               method which used an INT 10h function added by the
  121. X               EGA which caused no harm if an EGA was not
  122. X               installed.  At the time I read about it I was not
  123. X               really interested in EGA and now that I am I can't
  124. X               find the article.  I also don't have access to EGA
  125. X               documentation so I can't even figure out which
  126. X               routine was being used.    If you know how to detect
  127. X               EGA add the code to ScrInitialize.  Most EGA's
  128. X               will work as CGA with the video signal being
  129. X               disabled but this is not required with the EGA.
  130. X
  131. X     -    VGA:           Currently VGA color modes are treated as CGA.  I've
  132. X               never seen a VGA or any docs on it.  If you've got
  133. X               one, I hope this code works.  If it doesn't,
  134. X               I'm sorry, but I can't help.
  135. X
  136. X
  137. X                 Room for Improvement
  138. X                 ====================
  139. X
  140. X   The functions included in this package provide the basics for developing
  141. X   an application using a windowed environment.  There is certainly room
  142. X   for improvement and I encourage you to enhance the functionality of
  143. X   this package.  Some suggestions:
  144. X
  145. X    -  Enhance the Move and Hide window functions to support windows which
  146. X       are not fully visible (i.e. partially overlayed).
  147. X
  148. X    -  Use these functions to develop a higher level of support for things
  149. X       like 123 style menus, pull down menus, data entry forms, etc.
  150. X
  151. X    -  Speed up the TextOut functions.    These functions rely on the ROM
  152. X       BIOS character out routines as a result of my desire to stay 100%
  153. X       with 'C' code.  I was tempted many times to rip out ScrTextOut and
  154. X       replace it with assembly code which directly accessed the hardware.
  155. X       I've resisted only because the BIOS code is tolerable in most
  156. X       situations and this code is much more portable than assembly code.
  157. X       With higher speed machines becoming more commonplace this problem
  158. X       may diminish.
  159. X
  160. X   I intend to work on some of these enhancements as time permits and I'm
  161. X   sure you can think of many more.  I would be very pleased if people
  162. X   making fixes and enhancements to this code would communicate their work
  163. X   to me.  If we all work together we may be able to come up with a public
  164. X   domain package which rivals those expensive commercial versions.
  165. X
  166. X                  Disclaimer
  167. X                  ==========
  168. X
  169. X   Many people in the software industry are quite happy to sell you
  170. X   software while assuming no responsibility for its functionality or
  171. X   usefulness.    I am happy to give you this software but I also cannot
  172. X   accept any responsibility for it.  I've tested this code and to the best
  173. X   of my knowledge it works and contains no errors.  I simply state that I
  174. X   think it is both functional and useful, I do not guarantee it.  You need
  175. X   to test the code to determine if it will be useful to you.  If you
  176. X   encounter problems with it, fix them.  That's why you wanted the source
  177. X   in the first place, right?
  178. X
  179. X                 Bob Withers
  180. X                  649 Meadowbrook St
  181. X                  Allen, Texas 75002
  182. X
  183. X             Functions Available in WIN.C
  184. X             ============================
  185. X
  186. WinExplodeWindow       Draws an exploding window on the screen. The
  187. X               screen area behind the window is not saved, the
  188. X               window is simply drawn.
  189. X
  190. WinDrawWindow           Draws a window on the screen without saving the
  191. X               screen area behind the window.
  192. X
  193. WinCreateWindow        Creates a screen window and displays it at the
  194. X               requested location.  The are behind the window
  195. X               is saved and will be restored when the window
  196. X               is destroyed.
  197. X
  198. WinDestroyWindow       Destroys a previously created window.  The
  199. X               saved screen area is restored and all resources
  200. X               allocated to support the window are freed.
  201. X
  202. WinScrollWindowUp      Scrolls a window up one line.
  203. X
  204. WinScrollWindowDown    Scrolls a window down one line.
  205. X
  206. WinSetCursorPos        Positions the cursor either relative to an
  207. X               open window or to absolute screen locations.
  208. X
  209. WinClearScreen           Clears a window (or the entire screen) to the
  210. X               requested color attribute.
  211. X
  212. WinTextOut           Displays a string within the requested window
  213. X               at the current cursor location (for the
  214. X               selected window).  If the string would extend
  215. X               beyond the window it is truncated.
  216. X
  217. WinCenterText           Centers a text string within a window on the
  218. X               requested row.
  219. X
  220. WinMoveWindow           Moves an existing window to a new location on
  221. X               the screen.  There are a couple of caveats in
  222. X               this version of the package:
  223. X             1)  The window must be fully visible (i.e. no
  224. X                 other window overlaying any part of it)
  225. X                 for this routine to work properly.
  226. X             2)  It is the callers responsibility to
  227. X                 insure that the moved window will still
  228. X                 fit on the screen at the new location.
  229. X             3)  The size of the window may not be changed,
  230. X                 it can only be moved to a new location.
  231. X
  232. WinGetWindowRow        Returns the absolute row (1 relative) of the
  233. X               selected window.
  234. X
  235. WinGetWindowCol        Returns the absolute column (1 relative) of
  236. X               the selected window.
  237. X
  238. WinGetWindowWidth      Returns the number of columns available for
  239. X               text within the selected window. If the
  240. X               window was created with a border, this value
  241. X               will be two less than the width specified in
  242. X               the create call.
  243. X
  244. WinGetWindowHeight     Returns the number of rows available for text
  245. X               within the selected window.  If the window was
  246. X               created with a border, this value will be two
  247. X               less than the height specified in the create
  248. X               call.
  249. X
  250. WinGetWindowClr        Returns the background color of a window.
  251. X
  252. WinGetWindowBdrClr     Returns the border color of a window.
  253. X
  254. WinGetBorderType       Returns the border type of a window.
  255. X
  256. WinHideWindow           Removes a window from the screen.  The window
  257. X               still exists and is saved in it's current state.
  258. X               All the caveats listed under WinMoveWindow
  259. X               apply to the function.
  260. X
  261. WinShowWindow           Shows a window which is hidden and frees the
  262. X               buffer used to hold the current state of the
  263. X               window.
  264. X
  265. WinInitialize           Initializes the window package.    This function
  266. X               must be called once before any of the other
  267. X               functions in this package are used.  It should
  268. X               NEVER be called while windows are open or the
  269. X               buffers allocated to support them will be
  270. X               stranded and their handles will no longer be
  271. X               valid.
  272. X
  273. WinTerminate           Assures that all open windows are closed.
  274. X
  275. X
  276. X            Functions Available in SCRIO.C
  277. X            ==============================
  278. X
  279. ScrGetRectSize          Calculates the number of bytes required to
  280. X              store a screen image.
  281. X
  282. ScreenClearRect       Clears a rectangle on the screen to the passed
  283. X              color value.
  284. X
  285. ScrSaveRect          Save a screen rectangle in a buffer provided
  286. X              by the caller.
  287. X
  288. ScrRestoreRect          Restores a saved screen image from a buffer
  289. X              passed by the caller.
  290. X
  291. ScrSetCursorPos       Positions the cursor to an absolute screen
  292. X              location (1 relative).
  293. X
  294. ScrGetCursorPos       Gets the absolute screen location of the cursor.
  295. X
  296. ScrCursorOn          Enables the screen cursor.
  297. X
  298. ScrCursorOff          Disables the screen cursor.
  299. X
  300. ScrTextOut          Displays a text string to the video screen.
  301. X
  302. ScrDrawRect          Draws the selected border around a screen
  303. X              retangle.
  304. X
  305. ScrInitialize          Determines the video equipment installed on the
  306. X              machine. This routine is called by WinInitialize
  307. X              and does not need to invoked by the user code.
  308. X
  309. END_OF_FILE
  310. if test 11554 -ne `wc -c <'win.doc'`; then
  311.     echo shar: \"'win.doc'\" unpacked with wrong size!
  312. fi
  313. chmod +x 'win.doc'
  314. # end of 'win.doc'
  315. fi
  316. if test -f 'win.c' -a "${1}" != "-c" ; then 
  317.   echo shar: Will not clobber existing file \"'win.c'\"
  318. else
  319. echo shar: Extracting \"'win.c'\" \(25998 characters\)
  320. sed "s/^X//" >'win.c' <<'END_OF_FILE'
  321. X
  322. X/***************************************************************************/
  323. X/* WIN        - Routines which provide windowing functionality           */
  324. X/*                                       */
  325. X/*                                       */
  326. X/*                                       */
  327. X/***************************************************************************/
  328. X/*                 Modification Log                   */
  329. X/***************************************************************************/
  330. X/* Version   Date   Programmer     -----------  Description  --------------- */
  331. X/*                                       */
  332. X/* V01.00   112787  Bob Withers  Program intially complete.           */
  333. X/*                                       */
  334. X/*                                       */
  335. X/***************************************************************************/
  336. X
  337. X#include <stdlib.h>
  338. X#include <stddef.h>
  339. X#include <string.h>
  340. X#include "win.h"
  341. X
  342. X#define MAX_WINDOWS           20
  343. X
  344. X
  345. struct sWinData
  346. X{
  347. X    BYTE        cRow;
  348. X    BYTE        cCol;
  349. X    BYTE        cWidth;
  350. X    BYTE        cHeight;
  351. X    BYTE        cWinWidth;
  352. X    BYTE        cWinHeight;
  353. X    BYTE        cWinClr;
  354. X    BYTE        cBdrType;
  355. X    BYTE        cBdrClr;
  356. X    BYTE        cCurRow;
  357. X    BYTE        cCurCol;
  358. X    char           *pHidden;
  359. X    char        cSaveData[1];
  360. X};
  361. typedef struct sWinData WINDATA;
  362. typedef struct sWinData *PWINDATA;
  363. X
  364. static PWINDATA     WinHandle[MAX_WINDOWS + 1];
  365. X
  366. X
  367. X/***************************************************************************/
  368. X/*  WinCvtHandle    - Convert a window handle into a pointer to the       */
  369. X/*              window information data structure.           */
  370. X/*  Parms:                                   */
  371. X/*    hWnd        - handle to the window                   */
  372. X/*                                       */
  373. X/*  Return Value:     pointer to WINDATA or NULL if invalid handle       */
  374. X/***************************************************************************/
  375. X
  376. static PWINDATA near pascal WinCvtHandle(hWnd)
  377. HWND       hWnd;
  378. X{
  379. X    if (hWnd < 0 || hWnd > MAX_WINDOWS)
  380. X    return(NULL);
  381. X    return(WinHandle[hWnd]);
  382. X}
  383. X
  384. X
  385. X/***************************************************************************/
  386. X/*  WinGetHandle    - Return an unused window handle.               */
  387. X/*                                       */
  388. X/*  Parms:          None                           */
  389. X/*                                       */
  390. X/*  Return Value:     Window handle or NULL if none available           */
  391. X/***************************************************************************/
  392. X
  393. static HWND near pascal WinGetHandle()
  394. X{
  395. X    register int     i;
  396. X
  397. X    for (i = 1; i <= MAX_WINDOWS; ++i)
  398. X    {
  399. X    if (NULL == WinHandle[i])
  400. X        return(i);
  401. X    }
  402. X    return(NULL);
  403. X}
  404. X
  405. X
  406. X/***************************************************************************/
  407. X/*  WinExplodeWindow - Draws an exploded window on the screen.           */
  408. X/*                                       */
  409. X/*  Parms:                                   */
  410. X/*    nRow        - Top row of requested window (1 relative)           */
  411. X/*    nCol        - Left column of requested window (1 relative)       */
  412. X/*    nWidth        - Width (in columns) of requested window           */
  413. X/*    nHeight        - Height (in rows) of requested window           */
  414. X/*    nWinClr        - Color of the window background               */
  415. X/*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  416. X/*              NO_BOX                       */
  417. X/*              DBL_LINE_TOP_BOTTOM                   */
  418. X/*              DBL_LINE_SIDES                   */
  419. X/*              DBL_LINE_ALL_SIDES                   */
  420. X/*              SNGL_LINE_ALL_SIDES                   */
  421. X/*              GRAPHIC_BOX                       */
  422. X/*              NO_WIND_BORDER                   */
  423. X/*    nBdrClr        - Color or the window border               */
  424. X/*                                       */
  425. X/*  Return Value:     None                           */
  426. X/***************************************************************************/
  427. X
  428. void near pascal WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  429. X                  nWinClr, nBdrType, nBdrClr)
  430. short       nRow, nCol, nWidth, nHeight;
  431. short       nWinClr, nBdrType, nBdrClr;
  432. X{
  433. X    register short     nLRR, nLRC, nX1, nY1, nX2, nY2;
  434. X
  435. X    nLRR  = nRow + nHeight - 1;
  436. X    nLRC  = nCol + nWidth - 1;
  437. X    nX1   = (nRow + (nHeight >> 1)) - 1;
  438. X    nY1   = (nCol + (nWidth >> 1)) - 3;
  439. X    nX2   = nX1 + 2;
  440. X    nY2   = nY1 + 5;
  441. X    while (TRUE)
  442. X    {
  443. X    ScrClearRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1, nWinClr);
  444. X    ScrDrawRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1,
  445. X            nBdrClr, nBdrType);
  446. X    if (nX1 == nRow && nY1 == nCol && nX2 == nLRR && nY2 == nLRC)
  447. X        break;
  448. X    nX1 = (nX1 - 1 < nRow) ? nRow : nX1 - 1;
  449. X    nY1 = (nY1 - 3 < nCol) ? nCol : nY1 - 3;
  450. X    nX2 = (nX2 + 1 > nLRR) ? nLRR : nX2 + 1;
  451. X    nY2 = (nY2 + 3 > nLRC) ? nLRC : nY2 + 3;
  452. X    }
  453. X    return;
  454. X}
  455. X
  456. X
  457. X
  458. X/***************************************************************************/
  459. X/*  WinDrawWindow    - Draws a window on the screen without creating the   */
  460. X/*               WINDATA structure or saving the previous screen       */
  461. X/*               contents.                       */
  462. X/*                                       */
  463. X/*  Parms:                                   */
  464. X/*    nRow        - Top row of requested window (1 relative)           */
  465. X/*    nCol        - Left column of requested window (1 relative)       */
  466. X/*    nWidth        - Width (in columns) of requested window           */
  467. X/*    nHeight        - Height (in rows) of requested window           */
  468. X/*    nWinClr        - Color of the window background               */
  469. X/*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  470. X/*              NO_BOX                       */
  471. X/*              DBL_LINE_TOP_BOTTOM                   */
  472. X/*              DBL_LINE_SIDES                   */
  473. X/*              DBL_LINE_ALL_SIDES                   */
  474. X/*              SNGL_LINE_ALL_SIDES                   */
  475. X/*              GRAPHIC_BOX                       */
  476. X/*              NO_WIND_BORDER                   */
  477. X/*    nBdrClr        - Color or the window border               */
  478. X/*    bExplodeWin   - Boolean value requesting either a pop-up or       */
  479. X/*              exploding window                       */
  480. X/*              TRUE     ==> Exploding window               */
  481. X/*              FALSE  ==> Pop-up window               */
  482. X/*                                       */
  483. X/*  Return Value:     None                           */
  484. X/***************************************************************************/
  485. X
  486. void pascal WinDrawWindow(nRow, nCol, nWidth, nHeight,
  487. X              nWinClr, nBdrType, nBdrClr, bExplodeWin)
  488. short       nRow, nCol, nWidth, nHeight;
  489. short       nWinClr, nBdrType, nBdrClr;
  490. short       bExplodeWin;
  491. X{
  492. X    if (bExplodeWin)
  493. X    WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  494. X             nWinClr, nBdrType, nBdrClr);
  495. X    else
  496. X    {
  497. X    ScrClearRect(nRow, nCol, nWidth, nHeight, nWinClr);
  498. X    ScrDrawRect(nRow, nCol, nWidth, nHeight, nBdrClr, nBdrType);
  499. X    }
  500. X    return;
  501. X}
  502. X
  503. X
  504. X/***************************************************************************/
  505. X/*  WinCreateWindow - Create a window with the requested attributes and    */
  506. X/*              return a handle which may be used to identify this   */
  507. X/*              particular window in future calls.           */
  508. X/*  Parms:                                   */
  509. X/*    nRow        - Top row of requested window (1 relative)           */
  510. X/*    nCol        - Left column of requested window (1 relative)       */
  511. X/*    nWidth        - Width (in columns) of requested window           */
  512. X/*    nHeight        - Height (in rows) of requested window           */
  513. X/*    nWinClr        - Color of the window background               */
  514. X/*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  515. X/*              NO_BOX                       */
  516. X/*              DBL_LINE_TOP_BOTTOM                   */
  517. X/*              DBL_LINE_SIDES                   */
  518. X/*              DBL_LINE_ALL_SIDES                   */
  519. X/*              SNGL_LINE_ALL_SIDES                   */
  520. X/*              GRAPHIC_BOX                       */
  521. X/*              NO_WIND_BORDER                   */
  522. X/*    nBdrClr        - Color or the window border               */
  523. X/*    bExplodeWin   - Boolean value requesting either a pop-up or       */
  524. X/*              exploding window                       */
  525. X/*              TRUE     ==> Exploding window               */
  526. X/*              FALSE  ==> Pop-up window               */
  527. X/*                                       */
  528. X/*  Return Value:                               */
  529. X/*    hWnd        - Handle of the created window or NULL if an error       */
  530. X/*              prevented the creation                   */
  531. X/***************************************************************************/
  532. X
  533. HWND pascal WinCreateWindow(nRow, nCol, nWidth, nHeight,
  534. X                nWinClr, nBdrType, nBdrClr, bExplodeWin)
  535. short       nRow, nCol, nWidth, nHeight;
  536. short       nWinClr, nBdrType, nBdrClr;
  537. short       bExplodeWin;
  538. X{
  539. X    register PWINDATA         pWinData;
  540. X    auto     HWND         hWnd;
  541. X
  542. X    hWnd = WinGetHandle();
  543. X    if (NULL == hWnd)
  544. X    return(hWnd);
  545. X    pWinData = (PWINDATA) malloc(sizeof(WINDATA)
  546. X                   + ScrGetRectSize(nWidth, nHeight));
  547. X    if ((PWINDATA) NULL != pWinData)
  548. X    {
  549. X    WinHandle[hWnd]    = pWinData;
  550. X    pWinData->cRow       = (BYTE) nRow;
  551. X    pWinData->cCol       = (BYTE) nCol;
  552. X    pWinData->cWidth   = pWinData->cWinWidth  = (BYTE) nWidth;
  553. X    pWinData->cHeight  = pWinData->cWinHeight = (BYTE) nHeight;
  554. X    pWinData->cWinClr  = (BYTE) nWinClr;
  555. X    pWinData->cBdrType = (BYTE) nBdrType;
  556. X    pWinData->cBdrClr  = (BYTE) nBdrClr;
  557. X    pWinData->cCurRow  = pWinData->cCurCol = (BYTE) 1;
  558. X    pWinData->pHidden  = NULL;
  559. X    if (NO_WIND_BORDER != nBdrType)
  560. X    {
  561. X        pWinData->cWinWidth  -= 2;
  562. X        pWinData->cWinHeight -= 2;
  563. X    }
  564. X    ScrSaveRect(nRow, nCol, nWidth, nHeight, pWinData->cSaveData);
  565. X    if (bExplodeWin)
  566. X        WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  567. X                 nWinClr, nBdrType, nBdrClr);
  568. X    else
  569. X    {
  570. X        ScrClearRect(nRow, nCol, nWidth, nHeight, nWinClr);
  571. X        ScrDrawRect(nRow, nCol, nWidth, nHeight, nBdrClr, nBdrType);
  572. X    }
  573. X    WinSetCursorPos((HWND) pWinData, 1, 1);
  574. X    }
  575. X    return(hWnd);
  576. X}
  577. X
  578. X
  579. X/***************************************************************************/
  580. X/*  WinDestoryWindow - Destroy the window represented by hWnd and replace  */
  581. X/*               the previous screen contents saved when the window  */
  582. X/*               was created.                       */
  583. X/*  Parms:                                   */
  584. X/*    hWnd        - Handle to the window to be destroyed           */
  585. X/*                                       */
  586. X/*  Return Value:     TRUE => window destroyed, FALSE => invalid handle    */
  587. X/***************************************************************************/
  588. X
  589. BOOL pascal WinDestroyWindow(hWnd)
  590. HWND       hWnd;
  591. X{
  592. X    register PWINDATA        pWinData;
  593. X
  594. X    pWinData = WinCvtHandle(hWnd);
  595. X    if (NULL == pWinData)
  596. X    return(FALSE);
  597. X    ScrRestoreRect(pWinData->cRow, pWinData->cCol, pWinData->cWidth,
  598. X           pWinData->cHeight, pWinData->cSaveData);
  599. X    if (NULL != pWinData->pHidden)
  600. X    free(pWinData->pHidden);
  601. X    free((char *) pWinData);
  602. X    WinHandle[hWnd] = NULL;
  603. X    return(TRUE);
  604. X}
  605. X
  606. X
  607. X/***************************************************************************/
  608. X/*  WinScrollWindowUp  - Scrolls the requested window up one line.       */
  609. X/*                                       */
  610. X/*  Parms:                                   */
  611. X/*    hWnd        - Handle to the window to be scrolled           */
  612. X/*                                       */
  613. X/*  Return Value:     None                           */
  614. X/***************************************************************************/
  615. X
  616. void pascal WinScrollWindowUp(hWnd)
  617. HWND         hWnd;
  618. X{
  619. X    register PWINDATA        pWinData;
  620. X    auto     short        nRow, nCol;
  621. X
  622. X    pWinData = WinCvtHandle(hWnd);
  623. X    if (NULL == pWinData)
  624. X    return;
  625. X    if (NULL == pWinData->pHidden)
  626. X    {
  627. X    nRow = pWinData->cRow;
  628. X    nCol = pWinData->cCol;
  629. X    if (NO_WIND_BORDER != pWinData->cBdrType)
  630. X    {
  631. X        nRow++;
  632. X        nCol++;
  633. X    }
  634. X    ScrScrollRectUp(nRow, nCol, pWinData->cWinWidth,
  635. X            pWinData->cWinHeight, 1, pWinData->cWinClr);
  636. X    }
  637. X    return;
  638. X}
  639. X
  640. X
  641. X/***************************************************************************/
  642. X/*  WinScrollWindowDown - Scrolls the requested window down one line.       */
  643. X/*                                       */
  644. X/*  Parms:                                   */
  645. X/*    hWnd        - Handle to the window to be scrolled           */
  646. X/*                                       */
  647. X/*  Return Value:     None                           */
  648. X/***************************************************************************/
  649. X
  650. void pascal WinScrollWindowDown(hWnd)
  651. HWND         hWnd;
  652. X{
  653. X    register PWINDATA        pWinData;
  654. X    auto     short        nRow, nCol;
  655. X
  656. X    pWinData = WinCvtHandle(hWnd);
  657. X    if (NULL == pWinData)
  658. X    return;
  659. X    if (NULL == pWinData->pHidden)
  660. X    {
  661. X    nRow = pWinData->cRow;
  662. X    nCol = pWinData->cCol;
  663. X    if (NO_WIND_BORDER != pWinData->cBdrType)
  664. X    {
  665. X        nRow++;
  666. X        nCol++;
  667. X    }
  668. X    ScrScrollRectDown(nRow, nCol, pWinData->cWinWidth,
  669. X              pWinData->cWinHeight, 1, pWinData->cWinClr);
  670. X    }
  671. X    return;
  672. X}
  673. X
  674. X
  675. X/***************************************************************************/
  676. X/*  WinSetCursorPos - Position the cursor relative to the selected window. */
  677. X/*              The upper left hand corner of the window is (1,1)    */
  678. X/*                                       */
  679. X/*  Parms:                                   */
  680. X/*    hWnd        - Handle to the window to position the cusor in       */
  681. X/*    nRow        - Row to position cursor to within window (1 relative) */
  682. X/*    nCol        - Col to position cursor to within window (1 relative) */
  683. X/*                                       */
  684. X/*  Return Value:     None                           */
  685. X/***************************************************************************/
  686. X
  687. void pascal WinSetCursorPos(hWnd, nRow, nCol)
  688. HWND        hWnd;
  689. short        nRow, nCol;
  690. X{
  691. X    register PWINDATA        pWinData;
  692. X    auto     short        nMaxRow, nMaxCol;
  693. X
  694. X    if (NULL == hWnd)
  695. X    {
  696. X    ScrSetCursorPos(nRow, nCol);
  697. X    return;
  698. X    }
  699. X    pWinData = WinCvtHandle(hWnd);
  700. X    if (NULL == pWinData)
  701. X    return;
  702. X    if (nRow > pWinData->cWinHeight && nCol > pWinData->cWinWidth)
  703. X    return;
  704. X    pWinData->cCurRow = (BYTE) nRow;
  705. X    pWinData->cCurCol = (BYTE) nCol;
  706. X    nRow = nRow + pWinData->cRow - 1;
  707. X    nCol = nCol + pWinData->cCol - 1;
  708. X    if (NO_WIND_BORDER != pWinData->cBdrType)
  709. X    {
  710. X    ++nRow;
  711. X    ++nCol;
  712. X    }
  713. X    ScrSetCursorPos(nRow, nCol);
  714. X    return;
  715. X}
  716. X
  717. X
  718. X/***************************************************************************/
  719. X/*  WinClearScreen - Clear a window to the desired color.           */
  720. X/*                                       */
  721. X/*  Parms:                                   */
  722. X/*    hWnd       - Handle to the window to be cleared            */
  723. X/*             (A handle of NULL clears the entire screen)       */
  724. X/*    nColor       - Color to be used in clearing the window           */
  725. X/*                                       */
  726. X/*  Return Value:    None                           */
  727. X/***************************************************************************/
  728. X
  729. void pascal WinClearScreen(hWnd, nColor)
  730. HWND        hWnd;
  731. short        nColor;
  732. X{
  733. X    register PWINDATA        pWinData;
  734. X    auto     short        nRow, nCol;
  735. X
  736. X    if (NULL == hWnd)
  737. X    ScrClearRect(1, 1, 80, 25, nColor);
  738. X    else
  739. X    {
  740. X    pWinData = WinCvtHandle(hWnd);
  741. X    if (NULL == pWinData)
  742. X        return;
  743. X    nRow     = pWinData->cRow;
  744. X    nCol     = pWinData->cCol;
  745. X    if (NO_WIND_BORDER != pWinData->cBdrType)
  746. X    {
  747. X        ++nRow;
  748. X        ++nCol;
  749. X    }
  750. X    pWinData->cWinClr = (BYTE) nColor;
  751. X    ScrClearRect(nRow, nCol, pWinData->cWinWidth, pWinData->cWinHeight,
  752. X             pWinData->cWinClr);
  753. X    }
  754. X    return;
  755. X}
  756. X
  757. X
  758. X/***************************************************************************/
  759. X/*  WinTextOut       - Display a string to the requested window at the       */
  760. X/*             current cursor location (for that window) using the   */
  761. X/*             passed color attribute.                   */
  762. X/*             If the string extends beyond the boundries of the       */
  763. X/*             window it will be truncated.               */
  764. X/*  Parms:                                   */
  765. X/*    hWnd       - Handle of the window                   */
  766. X/*    pStr       - Pointer to the NULL terminated string to display       */
  767. X/*    nAttr       - Color attribute to be used in displaying the string   */
  768. X/*                                       */
  769. X/*  Return Value:    None                           */
  770. X/***************************************************************************/
  771. X
  772. void pascal WinTextOut(hWnd, pStr, nAttr)
  773. HWND        hWnd;
  774. char       *pStr;
  775. short        nAttr;
  776. X{
  777. X    register PWINDATA    pWinData;
  778. X    auto     short    nCount;
  779. X    auto     short    nRow, nCol;
  780. X
  781. X    pWinData = WinCvtHandle(hWnd);
  782. X    if (NULL == pWinData)
  783. X    return;
  784. X    ScrGetCursorPos(&nRow, &nCol);
  785. X    WinSetCursorPos(hWnd, pWinData->cCurRow, pWinData->cCurCol);
  786. X    nCount = pWinData->cWinWidth - pWinData->cCurCol + 1;
  787. X    ScrTextOut(pStr, nAttr, nCount);
  788. X    ScrSetCursorPos(nRow, nCol);
  789. X    return;
  790. X}
  791. X
  792. X
  793. X/***************************************************************************/
  794. X/*  WinCenterText  - Centers a text string in a window.            */
  795. X/*                                       */
  796. X/*  Parms:                                   */
  797. X/*    hWnd       - Handle of the window                   */
  798. X/*    nRow       - Window row to place the string on               */
  799. X/*    pStr       - Pointer to the string to be displayed           */
  800. X/*    nColor       - Color attribute used to display the string        */
  801. X/*                                       */
  802. X/*  Return Value:    None                           */
  803. X/***************************************************************************/
  804. void pascal WinCenterText(hWnd, nRow, pStr, nColor)
  805. HWND        hWnd;
  806. short        nRow;
  807. char       *pStr;
  808. short        nColor;
  809. X{
  810. X    if (NULL == WinCvtHandle(hWnd))
  811. X    return;
  812. X    WinSetCursorPos(hWnd, nRow, (WinGetWindowWidth(hWnd) - strlen(pStr)) / 2);
  813. X    WinTextOut(hWnd, pStr, nColor);
  814. X    return;
  815. X}
  816. X
  817. X
  818. X/***************************************************************************/
  819. X/*  WinMoveWindow  - Move an existing window to a new screen location.       */
  820. X/*             In this version the window to be moved MUST be fully  */
  821. X/*             visible on the screen for WinMoveWindow to perform    */
  822. X/*             properly.    If the window being moved is completely or */
  823. X/*             partially under another window the screen will not    */
  824. X/*             be left in the correct state (i.e. garbage on screen).*/
  825. X/*             It is the callers responsibility to insure that the   */
  826. X/*             window is not being moved off the screen.    Even with  */
  827. X/*             these restriction this can be a handy routine and is  */
  828. X/*             included for that reason.    A future release of the    */
  829. X/*             package may fix these shortcomings.           */
  830. X/*                                       */
  831. X/*  Parms:                                   */
  832. X/*    hWnd       - Handle to the window to be moved               */
  833. X/*    nRow       - Move the window to this row               */
  834. X/*    nCol       - Move the window to this column               */
  835. X/*                                       */
  836. X/*  Return Value:    None                           */
  837. X/***************************************************************************/
  838. X
  839. void pascal WinMoveWindow(hWnd, nRow, nCol)
  840. HWND        hWnd;
  841. short        nRow, nCol;
  842. X{
  843. X    register PWINDATA        pWinData;
  844. X    register char       *pBuf;
  845. X
  846. X    pWinData = WinCvtHandle(hWnd);
  847. X    if (NULL == pWinData)
  848. X    return;
  849. X    if (NULL != pWinData->pHidden)
  850. X    {
  851. X    pWinData->cRow = (BYTE) nRow;
  852. X    pWinData->cCol = (BYTE) nCol;
  853. X    return;
  854. X    }
  855. X    pBuf     = malloc(ScrGetRectSize(pWinData->cWidth, pWinData->cHeight));
  856. X    if (NULL != pBuf)
  857. X    {
  858. X    ScrSaveRect(pWinData->cRow, pWinData->cCol,
  859. X            pWinData->cWidth, pWinData->cHeight, pBuf);
  860. X    ScrRestoreRect(pWinData->cRow, pWinData->cCol,
  861. X               pWinData->cWidth, pWinData->cHeight,
  862. X               pWinData->cSaveData);
  863. X    ScrSaveRect(nRow, nCol, pWinData->cWidth, pWinData->cHeight,
  864. X            pWinData->cSaveData);
  865. X    ScrRestoreRect(nRow, nCol, pWinData->cWidth, pWinData->cHeight, pBuf);
  866. X    pWinData->cRow = (BYTE) nRow;
  867. X    pWinData->cCol = (BYTE) nCol;
  868. X    free(pBuf);
  869. X    }
  870. X    return;
  871. X}
  872. X
  873. X
  874. X/***************************************************************************/
  875. X/*  WinGetWindowRow - Returns the row value currently associated with the  */
  876. X/*              passed window handle.                   */
  877. X/*  Parms:                                   */
  878. X/*    hWnd       - Handle to the window                   */
  879. X/*                                       */
  880. X/*  Return Value:    Row the window currently resides at           */
  881. X/***************************************************************************/
  882. X
  883. short pascal WinGetWindowRow(hWnd)
  884. HWND        hWnd;
  885. X{
  886. X    register PWINDATA       pWinData;
  887. X
  888. X    pWinData = WinCvtHandle(hWnd);
  889. X    if (NULL == pWinData)
  890. X    return(0);
  891. X    return(pWinData->cRow);
  892. X}
  893. X
  894. X
  895. X/***************************************************************************/
  896. X/*  WinGetWindowCol - Returns the col value currently associated with the  */
  897. X/*              passed window handle.                   */
  898. X/*  Parms:                                   */
  899. X/*    hWnd       - Handle to the window                   */
  900. X/*                                       */
  901. X/*  Return Value:    Column the window currently resides at           */
  902. X/***************************************************************************/
  903. X
  904. short pascal WinGetWindowCol(hWnd)
  905. HWND        hWnd;
  906. X{
  907. X    register PWINDATA        pWinData;
  908. X
  909. X    pWinData = WinCvtHandle(hWnd);
  910. X    if (NULL == pWinData)
  911. X    return(0);
  912. X    return(pWinData->cCol);
  913. X}
  914. X
  915. X
  916. X/***************************************************************************/
  917. X/*  WinGetWindowWidth - Returns the column width of the passed window.       */
  918. X/*                                       */
  919. X/*  Parms:                                   */
  920. X/*    hWnd       - Handle to the window                   */
  921. X/*                                       */
  922. X/*  Return Value:    Number of columns in the window               */
  923. X/***************************************************************************/
  924. X
  925. short pascal WinGetWindowWidth(hWnd)
  926. HWND        hWnd;
  927. X{
  928. X    register PWINDATA       pWinData;
  929. X
  930. X    pWinData = WinCvtHandle(hWnd);
  931. X    if (NULL == pWinData)
  932. X    return(0);
  933. X    return(pWinData->cWinWidth);
  934. X}
  935. X
  936. X
  937. X/***************************************************************************/
  938. X/*  WinGetWindowHeight - Returns the number of rows in the passed window.  */
  939. X/*                                       */
  940. X/*  Parms:                                   */
  941. X/*    hWnd       - Handle to the window                   */
  942. X/*                                       */
  943. X/*  Return Value:    Number of rows in the window               */
  944. X/***************************************************************************/
  945. X
  946. short pascal WinGetWindowHeight(hWnd)
  947. HWND        hWnd;
  948. X{
  949. X    register PWINDATA        pWinData;
  950. X
  951. X    pWinData = WinCvtHandle(hWnd);
  952. X    if (NULL == pWinData)
  953. X    return(0);
  954. X    return(pWinData->cWinHeight);
  955. X}
  956. X
  957. X
  958. X/***************************************************************************/
  959. X/*  WinGetWindowClr - Get the window background color               */
  960. X/*                                       */
  961. X/*  Parms:                                   */
  962. X/*    hWnd       - Handle to the window                   */
  963. X/*                                       */
  964. X/*  Return Value:    Returns the attribute for the window color        */
  965. X/***************************************************************************/
  966. X
  967. short pascal WinGetWindowClr(hWnd)
  968. HWND        hWnd;
  969. X{
  970. X    register PWINDATA        pWinData;
  971. X
  972. X    pWinData = WinCvtHandle(hWnd);
  973. X    if (NULL == pWinData)
  974. X    return(0);
  975. X    return(pWinData->cWinClr);
  976. X}
  977. X
  978. X
  979. X/***************************************************************************/
  980. X/*  WinGetWindowBdrClr - Get the window border color               */
  981. X/*                                       */
  982. X/*  Parms:                                   */
  983. X/*    hWnd       - Handle to the window                   */
  984. X/*                                       */
  985. X/*  Return Value:    Returns the attribute for the window border color       */
  986. X/***************************************************************************/
  987. X
  988. short pascal WinGetWindowBdrClr(hWnd)
  989. HWND        hWnd;
  990. X{
  991. X    register PWINDATA        pWinData;
  992. X
  993. X    pWinData = WinCvtHandle(hWnd);
  994. X    if (NULL == pWinData)
  995. X    return(0);
  996. X    return(pWinData->cBdrClr);
  997. X}
  998. X
  999. X
  1000. X/***************************************************************************/
  1001. X/*  WinGetBorderType - Gets the border type of the passed window       */
  1002. X/*                                       */
  1003. X/*  Parms:                                   */
  1004. X/*    hWnd       - Handle to the window                   */
  1005. X/*                                       */
  1006. X/*  Return Value:    Returns the window border type               */
  1007. X/***************************************************************************/
  1008. X
  1009. short pascal WinGetBorderType(hWnd)
  1010. HWND        hWnd;
  1011. X{
  1012. X    register PWINDATA        pWinData;
  1013. X
  1014. X    pWinData = WinCvtHandle(hWnd);
  1015. X    if (NULL == pWinData)
  1016. X    return(0);
  1017. X    return(pWinData->cBdrType);
  1018. X}
  1019. X
  1020. X
  1021. X/***************************************************************************/
  1022. X/*  WinHideWindow  - Removes a window from the screen, saving it's         */
  1023. X/*             contents.    The window can later be placed back on       */
  1024. X/*             the screen via WinShowWindow().  Note that in this    */
  1025. X/*             release the window MUST be fully visible for this       */
  1026. X/*             operating to work correctly.               */
  1027. X/*  Parms:                                   */
  1028. X/*    hWnd       - Handle to the window                   */
  1029. X/*                                       */
  1030. X/*  Return Value:    TRUE => window hidden, FALSE => buf alloc failed       */
  1031. X/***************************************************************************/
  1032. X
  1033. BOOL pascal WinHideWindow(hWnd)
  1034. HWND        hWnd;
  1035. X{
  1036. X    register PWINDATA       pWinData;
  1037. X    auto     char      *pBuf;
  1038. X    auto     short       nBufSize;
  1039. X    auto     short       nRow, nCol, nWidth, nHeight;
  1040. X
  1041. X    pWinData = WinCvtHandle(hWnd);
  1042. X    if (NULL == pWinData)
  1043. X    return(FALSE);
  1044. X    nRow     = pWinData->cRow;
  1045. X    nCol     = pWinData->cCol;
  1046. X    nWidth   = pWinData->cWidth;
  1047. X    nHeight  = pWinData->cHeight;
  1048. X    nBufSize = ScrGetRectSize(nWidth, nHeight);
  1049. X    if (NULL != pWinData->pHidden)
  1050. X    free(pWinData->pHidden);
  1051. X    pBuf     = malloc(nBufSize);
  1052. X    if (NULL == pBuf)
  1053. X    return(FALSE);
  1054. X    ScrSaveRect(nRow, nCol, nWidth, nHeight, pBuf);
  1055. X    ScrRestoreRect(nRow, nCol, nWidth, nHeight, pWinData->cSaveData);
  1056. X    pWinData->pHidden = pBuf;
  1057. X    return(TRUE);
  1058. X}
  1059. X
  1060. X
  1061. X/***************************************************************************/
  1062. X/*  WinShowWindow  - Places a hidden window back on the screen and frees   */
  1063. X/*             the buffer used to hold the window image.           */
  1064. X/*  Parms:                                   */
  1065. X/*    hWnd       - Handle to the window                   */
  1066. X/*                                       */
  1067. X/*  Return Value:    TRUE => window shown, FALSE => window wasn't hidden   */
  1068. X/***************************************************************************/
  1069. X
  1070. BOOL pascal WinShowWindow(hWnd)
  1071. HWND         hWnd;
  1072. X{
  1073. X    register PWINDATA        pWinData;
  1074. X
  1075. X    pWinData = WinCvtHandle(hWnd);
  1076. X    if (NULL == pWinData)
  1077. X    return(FALSE);
  1078. X    if (NULL == pWinData->pHidden)
  1079. X    return(FALSE);
  1080. X    ScrRestoreRect(pWinData->cRow, pWinData->cCol, pWinData->cWidth,
  1081. X           pWinData->cHeight, pWinData->pHidden);
  1082. X    free(pWinData->pHidden);
  1083. X    pWinData->pHidden = NULL;
  1084. X    return(TRUE);
  1085. X}
  1086. X
  1087. X
  1088. X/***************************************************************************/
  1089. X/*  WinInitialize  - Init the windowing system.                */
  1090. X/*                                       */
  1091. X/*  Parms:         None                           */
  1092. X/*                                       */
  1093. X/*  Return Value:    None                           */
  1094. X/***************************************************************************/
  1095. X
  1096. void pascal WinInitialize()
  1097. X{
  1098. X    ScrInitialize();
  1099. X    memset((char *) WinHandle, NULL, sizeof(WinHandle));
  1100. X    return;
  1101. X}
  1102. X
  1103. X
  1104. X/***************************************************************************/
  1105. X/*  WinTerminate   - Clean up the windowing package               */
  1106. X/*                                       */
  1107. X/*  Parms:         None                           */
  1108. X/*                                       */
  1109. X/*  Return Value:    None                           */
  1110. X/***************************************************************************/
  1111. X
  1112. void pascal WinTerminate()
  1113. X{
  1114. X    register short     i;
  1115. X
  1116. X    for (i = 1; i <= MAX_WINDOWS; ++i)
  1117. X    {
  1118. X    if (WinHandle[i] != NULL)
  1119. X        WinDestroyWindow(i);
  1120. X    }
  1121. X    return;
  1122. X}
  1123. END_OF_FILE
  1124. if test 25998 -ne `wc -c <'win.c'`; then
  1125.     echo shar: \"'win.c'\" unpacked with wrong size!
  1126. fi
  1127. chmod +x 'win.c'
  1128. # end of 'win.c'
  1129. fi
  1130. if test -f 'win.h' -a "${1}" != "-c" ; then 
  1131.   echo shar: Will not clobber existing file \"'win.h'\"
  1132. else
  1133. echo shar: Extracting \"'win.h'\" \(4168 characters\)
  1134. sed "s/^X//" >'win.h' <<'END_OF_FILE'
  1135. X#ifndef WIN_H
  1136. X#define WIN_H
  1137. X
  1138. X#define ANSI_PROTO          1
  1139. X
  1140. X#ifndef TRUE
  1141. X#define TRUE              1
  1142. X#define FALSE              0
  1143. X#endif
  1144. X
  1145. X#define BLACK              0x0
  1146. X#define BLUE              0x1
  1147. X#define GREEN              0x2
  1148. X#define CYAN              0x3
  1149. X#define RED              0x4
  1150. X#define MAGENTA           0x5
  1151. X#define YELLOW              0x6
  1152. X#define WHITE              0x7
  1153. X#define REV_BLACK          0x0
  1154. X#define REV_BLUE          0x10
  1155. X#define REV_GREEN          0x20
  1156. X#define REV_CYAN          0x30
  1157. X#define REV_RED           0x40
  1158. X#define REV_MAGENTA          0x50
  1159. X#define REV_YELLOW          0x60
  1160. X#define REV_WHITE          0x70
  1161. X#define HI_INTENSITY          0x8
  1162. X#define BLINK              0x80
  1163. X
  1164. X#define NO_BOX              0
  1165. X#define DBL_LINE_TOP_BOTTOM   1
  1166. X#define DBL_LINE_SIDES          2
  1167. X#define DBL_LINE_ALL_SIDES    3
  1168. X#define SNGL_LINE_ALL_SIDES   4
  1169. X#define GRAPHIC_BOX          5
  1170. X#define NO_WIND_BORDER          99
  1171. X
  1172. X#define VIDEO_MONO          0
  1173. X#define VIDEO_CGA          1
  1174. X#define VIDEO_EGA          2
  1175. X#define VIDEO_VGA          3
  1176. X
  1177. typedef short              HWND;
  1178. typedef unsigned char          BYTE;
  1179. typedef short              BOOL;
  1180. X
  1181. X
  1182. X                 /*  WIN.C  */
  1183. X#if ANSI_PROTO
  1184. void     pascal    WinDrawWindow(short, short, short, short,
  1185. X                 short, short, short, short);
  1186. HWND     pascal    WinCreateWindow(short, short, short, short,
  1187. X                   short, short, short, short);
  1188. BOOL     pascal    WinDestroyWindow(HWND);
  1189. void     pascal    WinScrollWindowUp(HWND);
  1190. void     pascal    WinScrollWindowDown(HWND);
  1191. void     pascal    WinSetCursorPos(HWND, short, short);
  1192. void     pascal    WinClearScreen(HWND, short);
  1193. void     pascal    WinTextOut(HWND, char *, short);
  1194. void     pascal    WinCenterText(HWND, short, char *, short);
  1195. void     pascal    WinMoveWindow(HWND, short, short);
  1196. short     pascal    WinGetWindowRow(HWND);
  1197. short     pascal    WinGetWindowCol(HWND);
  1198. short     pascal    WinGetWindowWidth(HWND);
  1199. short     pascal    WinGetWindowHeight(HWND);
  1200. short     pascal    WinGetWindowClr(HWND);
  1201. short     pascal    WinGetWindowBdrClr(HWND);
  1202. short     pascal    WinGetBorderType(HWND);
  1203. BOOL     pascal    WinHideWindow(HWND);
  1204. BOOL     pascal    WinShowWindow(HWND);
  1205. void     pascal    WinInitialize(void);
  1206. void     pascal    WinTerminate(void);
  1207. X#else
  1208. void     pascal    WinDrawWindow();
  1209. HWND     pascal    WinCreateWindow();
  1210. BOOL     pascal    WinDestroyWindow();
  1211. void     pascal    WinScrollWindowUp();
  1212. void     pascal    WinScrollWindowDown();
  1213. void     pascal    WinSetCursorPos();
  1214. void     pascal    WinClearScreen();
  1215. void     pascal    WinTextOut();
  1216. void     pascal    WinCenterText();
  1217. void     pascal    WinMoveWindow();
  1218. short     pascal    WinGetWindowRow();
  1219. short     pascal    WinGetWindowCol();
  1220. short     pascal    WinGetWindowWidth();
  1221. short     pascal    WinGetWindowHeight();
  1222. short     pascal    WinGetWindowClr();
  1223. short     pascal    WinGetWindowBdrClr();
  1224. short     pascal    WinGetBorderType();
  1225. BOOL     pascal    WinHideWindow();
  1226. BOOL     pascal    WinShowWindow();
  1227. void     pascal    WinInitialize();
  1228. void     pascal    WinTerminate();
  1229. X#endif
  1230. X
  1231. X                /*  SCRIO.C  */
  1232. X#if ANSI_PROTO
  1233. short     pascal    ScrGetRectSize(short, short);
  1234. void     pascal    ScrClearRect(short, short, short, short, short);
  1235. void     pascal    ScrSaveRect(short, short, short, short, char *);
  1236. void     pascal    ScrRestoreRect(short, short, short, short, char *);
  1237. void     pascal    ScrScrollRectUp(short, short, short, short,
  1238. X                   short, short);
  1239. void     pascal    ScrScrollRectDown(short, short, short, short,
  1240. X                     short, short);
  1241. void     pascal    ScrSetCursorPos(short, short);
  1242. void     pascal    ScrGetCursorPos(short *, short *);
  1243. void     pascal    ScrCursorOn(void);
  1244. void     pascal    ScrCursorOff(void);
  1245. void     pascal    ScrTextOut(char *, short, short);
  1246. void     pascal    ScrDrawRect(short, short, short, short, short, short);
  1247. void     pascal    ScrInitialize(void);
  1248. X#else
  1249. short     pascal    ScrGetRectSize();
  1250. void     pascal    ScrClearRect();
  1251. void     pascal    ScrSaveRect();
  1252. void     pascal    ScrRestoreRect();
  1253. void     pascal    ScrScrollRectUp();
  1254. void     pascal    ScrScrollRectDown();
  1255. void     pascal    ScrSetCursorPos();
  1256. void     pascal    ScrGetCursorPos();
  1257. void     pascal    ScrCursorOn();
  1258. void     pascal    ScrCursorOff();
  1259. void     pascal    ScrTextOut();
  1260. void     pascal    ScrDrawRect();
  1261. void     pascal    ScrInitialize();
  1262. X#endif
  1263. X
  1264. X#endif
  1265. X
  1266. END_OF_FILE
  1267. if test 4168 -ne `wc -c <'win.h'`; then
  1268.     echo shar: \"'win.h'\" unpacked with wrong size!
  1269. fi
  1270. chmod +x 'win.h'
  1271. # end of 'win.h'
  1272. fi
  1273. if test -f 'scrio.c' -a "${1}" != "-c" ; then 
  1274.   echo shar: Will not clobber existing file \"'scrio.c'\"
  1275. else
  1276. echo shar: Extracting \"'scrio.c'\" \(19021 characters\)
  1277. sed "s/^X//" >'scrio.c' <<'END_OF_FILE'
  1278. X
  1279. X/***************************************************************************/
  1280. X/* SCRIO    - Routines which directly access the video screen           */
  1281. X/*                                       */
  1282. X/*                                       */
  1283. X/*                                       */
  1284. X/***************************************************************************/
  1285. X/*                 Modification Log                   */
  1286. X/***************************************************************************/
  1287. X/* Version   Date   Programmer     -----------  Description  --------------- */
  1288. X/*                                       */
  1289. X/* V01.00   112787  Bob Withers  Program intially complete.           */
  1290. X/*                                       */
  1291. X/*                                       */
  1292. X/***************************************************************************/
  1293. X
  1294. X#include <stdlib.h>
  1295. X#include <stddef.h>
  1296. X#include <dos.h>
  1297. X#include <string.h>
  1298. X#include "win.h"
  1299. X
  1300. X#define MAXDIM(array)           (sizeof(array) / sizeof(array[0]))
  1301. X
  1302. X#define SCR_BYTES_PER_ROW       160
  1303. X#define CGA_MODE_SEL           0x3d8
  1304. X#define CGA_ENABLE           0x29
  1305. X#define CGA_DISABLE           0x21
  1306. X
  1307. X#define BIOS_VID_INT           0x10
  1308. X#define BIOS_VID_SET_CRTMODE       0
  1309. X#define BIOS_VID_SET_CURSORTYPE    1
  1310. X#define BIOS_VID_SET_CURSORPOS       2
  1311. X#define BIOS_VID_GET_CURSORPOS       3
  1312. X#define BIOS_VID_SCROLL_UP       6
  1313. X#define BIOS_VID_SCROLL_DOWN       7
  1314. X#define BIOS_VID_WRITE_CHATTR       9
  1315. X#define BIOS_VID_GET_CRTMODE       15
  1316. X
  1317. X
  1318. struct sBoxType
  1319. X{
  1320. X    BYTE        cUpperLeft;
  1321. X    BYTE        cLowerLeft;
  1322. X    BYTE        cUpperRight;
  1323. X    BYTE        cLowerRight;
  1324. X    BYTE        cLeft;
  1325. X    BYTE        cRight;
  1326. X    BYTE        cTop;
  1327. X    BYTE        cBottom;
  1328. X};
  1329. typedef struct sBoxType BOXTYPE;
  1330. X
  1331. X
  1332. unsigned        uScrSeg     = 0xb800;
  1333. unsigned        uCsrType    = 0x0107;
  1334. short            nCurrActivePage = 0;
  1335. short            nVideoCard    = VIDEO_CGA;
  1336. short            nScrCols    = 80;
  1337. X
  1338. X
  1339. X/***************************************************************************/
  1340. X/*  ScrCvtAttr      - Test for a monochrome video card and convert the       */
  1341. X/*            requested attribute to black & white as best we can    */
  1342. X/*            and still honor the callers request.           */
  1343. X/*  Parms:                                   */
  1344. X/*    nAttr      - The passed color attribute.                */
  1345. X/*                                       */
  1346. X/*  Return Value:   A converted black & white attribute if the current       */
  1347. X/*            video mode is monochrome.                   */
  1348. X/***************************************************************************/
  1349. X
  1350. static short near pascal ScrCvtAttr(nAttr)
  1351. register short      nAttr;
  1352. X{
  1353. X    short     nRev, nClr, nBlink, nIntensity;
  1354. X
  1355. X    if (VIDEO_MONO != nVideoCard)
  1356. X    return(nAttr);
  1357. X    nIntensity = nAttr & 0x40;
  1358. X    nBlink     = nAttr & 0x80;
  1359. X    nRev       = nAttr & 0x70;
  1360. X    nClr       = nAttr & 0x07;
  1361. X    if (REV_BLACK == nRev)
  1362. X    nClr = WHITE;
  1363. X    else
  1364. X    {
  1365. X    nRev = REV_WHITE;
  1366. X    nClr = BLACK;
  1367. X    }
  1368. X    return(nRev | nClr | nBlink | nIntensity);
  1369. X}
  1370. X
  1371. X
  1372. X/***************************************************************************/
  1373. X/*  ScrEnableVideoCGA - Test the current video equipment for a snowy CGA   */
  1374. X/*            card.  If running on a CGA enable/disable the       */
  1375. X/*            video signal based on the passed parameter which   */
  1376. X/*            MUST be one of the predefined constants CGA_ENABLE */
  1377. X/*            or CGA_DISABLE.  If the current video equipment is */
  1378. X/*            not a CGA, the routine returns without taking any  */
  1379. X/*            action.                        */
  1380. X/*  Parms:                                   */
  1381. X/*    nStatus          - Enable or disable the CGA video signal           */
  1382. X/*                CGA_ENABLE or CGA_DISABLE               */
  1383. X/*                                       */
  1384. X/*  Return Value:    None                           */
  1385. X/***************************************************************************/
  1386. X
  1387. static void pascal ScrEnableVideoCGA(nStatus)
  1388. short        nStatus;
  1389. X{
  1390. X    if (VIDEO_CGA == nVideoCard)
  1391. X    outp(CGA_MODE_SEL, nStatus);
  1392. X    return;
  1393. X}
  1394. X
  1395. X
  1396. X/***************************************************************************/
  1397. X/*  ScrGetRectSize - This routine will calculate and return the number of  */
  1398. X/*             bytes required to store a screen image which is nWidth*/
  1399. X/*             columns by nHeight rows.                   */
  1400. X/*  Parms:                                   */
  1401. X/*    nWidth       - Column width of the screen rectangle           */
  1402. X/*    nHeight       - Number of rows in the screen rectangle           */
  1403. X/*                                       */
  1404. X/*  Return Value:    Size in bytes required to store the screen rectangle  */
  1405. X/***************************************************************************/
  1406. X
  1407. short pascal ScrGetRectSize(nWidth, nHeight)
  1408. short        nWidth, nHeight;
  1409. X{
  1410. X    return(nWidth * nHeight * 2);
  1411. X}
  1412. X
  1413. X
  1414. X/***************************************************************************/
  1415. X/*  ScrClearRect - This routine will clear a screen rectangle to the       */
  1416. X/*           color attribute passed.                   */
  1417. X/*  Parms:                                   */
  1418. X/*    nRow     - Row of the screen rectangle                   */
  1419. X/*    nCol     - Column of the screen rectangle               */
  1420. X/*    nWidth     - Width in columns of the screen rectangle           */
  1421. X/*    nHeight     - Number of rows in the screen rectangle           */
  1422. X/*    nAttr     - Color attribute used to clear screen rectangle       */
  1423. X/*                                       */
  1424. X/*  Return Value:  None                            */
  1425. X/***************************************************************************/
  1426. X
  1427. void pascal ScrClearRect(nRow, nCol, nWidth, nHeight, nAttr)
  1428. short             nRow, nCol, nWidth, nHeight, nAttr;
  1429. X{
  1430. X    auto     union REGS     r;
  1431. X
  1432. X    nAttr  = ScrCvtAttr(nAttr);
  1433. X    r.h.ah = (BYTE) BIOS_VID_SCROLL_UP;
  1434. X    r.h.al = 0;
  1435. X    r.h.bh = (BYTE) nAttr;
  1436. X    r.h.ch = (BYTE) (nRow - 1);
  1437. X    r.h.cl = (BYTE) (nCol - 1);
  1438. X    r.h.dh = (BYTE) (nRow + nHeight - 2);
  1439. X    r.h.dl = (BYTE) (nCol + nWidth - 2);
  1440. X    int86(BIOS_VID_INT, &r, &r);
  1441. X    return;
  1442. X}
  1443. X
  1444. X
  1445. X/***************************************************************************/
  1446. X/*  ScrSaveRect - This routine will save a screen rectangle in a caller    */
  1447. X/*          supplied buffer area.  nRow, nCol define the row and       */
  1448. X/*          column of the upper left corner of the rectangle.       */
  1449. X/*  Parms:                                   */
  1450. X/*    nRow    - Row of the screen rectangle                   */
  1451. X/*    nCol    - Column of the screen rectangle               */
  1452. X/*    nWidth    - Width in columns of the screen rectangle           */
  1453. X/*    nHeight    - Number of rows in the screen rectangle           */
  1454. X/*    pBuf    - Buffer used to store the saved screen rectangle       */
  1455. X/*                                       */
  1456. X/*  Return Value:  None                            */
  1457. X/***************************************************************************/
  1458. X
  1459. void pascal ScrSaveRect(nRow, nCol, nWidth, nHeight, pBuf)
  1460. short       nRow, nCol, nWidth, nHeight;
  1461. char      *pBuf;
  1462. X{
  1463. X    register unsigned        uNumRows;
  1464. X    register unsigned        uColLen;
  1465. X    auto     unsigned        uScrOfs;
  1466. X    auto     unsigned        uBufSeg, uBufOfs;
  1467. X    auto     char far       *fpBuf;
  1468. X
  1469. X    uColLen = nWidth * 2;
  1470. X    uScrOfs = ((nRow - 1) * SCR_BYTES_PER_ROW) + (nCol - 1) * 2;
  1471. X    fpBuf   = (char far *) pBuf;
  1472. X    uBufSeg = FP_SEG(fpBuf);
  1473. X    uBufOfs = FP_OFF(fpBuf);
  1474. X    ScrEnableVideoCGA(CGA_DISABLE);
  1475. X    for (uNumRows = nHeight; uNumRows > 0; --uNumRows)
  1476. X    {
  1477. X    movedata(uScrSeg, uScrOfs, uBufSeg, uBufOfs, uColLen);
  1478. X    uScrOfs += SCR_BYTES_PER_ROW;
  1479. X    uBufOfs += uColLen;
  1480. X    }
  1481. X    ScrEnableVideoCGA(CGA_ENABLE);
  1482. X    return;
  1483. X}
  1484. X
  1485. X
  1486. X/***************************************************************************/
  1487. X/*  ScrRestoreRect - This routine will restore a screen rectangle from       */
  1488. X/*             a previously saved caller buffer.    nRow and nCol       */
  1489. X/*             define the upper left corner of the rectangle on       */
  1490. X/*             the screen and are not required to be the same       */
  1491. X/*             coordinates used in the save call.  nWidth and       */
  1492. X/*             nHeight should remain unchanged from the save call    */
  1493. X/*             but are not required to do so.               */
  1494. X/*  Parms:                                   */
  1495. X/*    nRow    - Row of the screen rectangle                   */
  1496. X/*    nCol    - Column of the screen rectangle               */
  1497. X/*    nWidth    - Width in columns of the screen rectangle           */
  1498. X/*    nHeight    - Number of rows in the screen rectangle           */
  1499. X/*    pBuf    - Buffer used to restore the saved screen rectangle       */
  1500. X/*                                       */
  1501. X/*  Return Value:  None                            */
  1502. X/***************************************************************************/
  1503. X
  1504. void pascal ScrRestoreRect(nRow, nCol, nWidth, nHeight, pBuf)
  1505. short       nRow, nCol, nWidth, nHeight;
  1506. char      *pBuf;
  1507. X{
  1508. X    register unsigned        uNumRows;
  1509. X    register unsigned        uColLen;
  1510. X    auto     unsigned        uScrOfs;
  1511. X    auto     unsigned        uBufSeg, uBufOfs;
  1512. X    auto     char far       *fpBuf;
  1513. X
  1514. X    uColLen = nWidth * 2;
  1515. X    uScrOfs = ((nRow - 1) * SCR_BYTES_PER_ROW) + (nCol - 1) * 2;
  1516. X    fpBuf   = (char far *) pBuf;
  1517. X    uBufSeg = FP_SEG(fpBuf);
  1518. X    uBufOfs = FP_OFF(fpBuf);
  1519. X    ScrEnableVideoCGA(CGA_DISABLE);
  1520. X    for (uNumRows = nHeight; uNumRows > 0; --uNumRows)
  1521. X    {
  1522. X    movedata(uBufSeg, uBufOfs, uScrSeg, uScrOfs, uColLen);
  1523. X    uScrOfs += SCR_BYTES_PER_ROW;
  1524. X    uBufOfs += uColLen;
  1525. X    }
  1526. X    ScrEnableVideoCGA(CGA_ENABLE);
  1527. X    return;
  1528. X}
  1529. X
  1530. X
  1531. X/***************************************************************************/
  1532. X/*  ScrScrollRectUp   - Scrolls a screen rectangle up the requested number */
  1533. X/*            of lines.                       */
  1534. X/*  Parms:                                   */
  1535. X/*    nRow    - Row of the screen rectangle                   */
  1536. X/*    nCol    - Column of the screen rectangle               */
  1537. X/*    nWidth    - Width in columns of the screen rectangle           */
  1538. X/*    nHeight    - Number of rows in the screen rectangle           */
  1539. X/*    nNoRows    - Number of rows to scroll                   */
  1540. X/*    nAttr    - Color attribute to fill blank line on bottom           */
  1541. X/*                                       */
  1542. X/*  Return Value:  None                            */
  1543. X/***************************************************************************/
  1544. X
  1545. void pascal ScrScrollRectUp(nRow, nCol, nWidth, nHeight, nNoRows, nAttr)
  1546. short     nRow, nCol, nWidth, nHeight, nNoRows, nAttr;
  1547. X{
  1548. X    auto     union REGS      r;
  1549. X
  1550. X    nAttr  = ScrCvtAttr(nAttr);
  1551. X    r.h.ah = BIOS_VID_SCROLL_UP;
  1552. X    r.h.al = (BYTE) nNoRows;
  1553. X    r.h.bh = (BYTE) nAttr;
  1554. X    r.h.ch = (BYTE) (nRow - 1);
  1555. X    r.h.cl = (BYTE) (nCol - 1);
  1556. X    r.h.dh = (BYTE) (nRow + nHeight - 2);
  1557. X    r.h.dl = (BYTE) (nCol + nWidth - 2);
  1558. X    int86(BIOS_VID_INT, &r, &r);
  1559. X    return;
  1560. X}
  1561. X
  1562. X
  1563. X/***************************************************************************/
  1564. X/*  ScrScrollRectDown - Scrolls a screen rectangle up the requested number */
  1565. X/*            of lines.                       */
  1566. X/*  Parms:                                   */
  1567. X/*    nRow    - Row of the screen rectangle                   */
  1568. X/*    nCol    - Column of the screen rectangle               */
  1569. X/*    nWidth    - Width in columns of the screen rectangle           */
  1570. X/*    nHeight    - Number of rows in the screen rectangle           */
  1571. X/*    nNoRows    - Number of rows to scroll                   */
  1572. X/*    nAttr    - Color attribute to fill blank lines on top           */
  1573. X/*                                       */
  1574. X/*  Return Value:  None                            */
  1575. X/***************************************************************************/
  1576. X
  1577. void pascal ScrScrollRectDown(nRow, nCol, nWidth, nHeight, nNoRows, nAttr)
  1578. short     nRow, nCol, nWidth, nHeight, nNoRows, nAttr;
  1579. X{
  1580. X    auto     union REGS      r;
  1581. X
  1582. X    nAttr  = ScrCvtAttr(nAttr);
  1583. X    r.h.ah = BIOS_VID_SCROLL_DOWN;
  1584. X    r.h.al = (BYTE) nNoRows;
  1585. X    r.h.bh = (BYTE) nAttr;
  1586. X    r.h.ch = (BYTE) (nRow - 1);
  1587. X    r.h.cl = (BYTE) (nCol - 1);
  1588. X    r.h.dh = (BYTE) (nRow + nHeight - 2);
  1589. X    r.h.dl = (BYTE) (nCol + nWidth - 2);
  1590. X    int86(BIOS_VID_INT, &r, &r);
  1591. X    return;
  1592. X}
  1593. X
  1594. X
  1595. X/***************************************************************************/
  1596. X/*  ScrSetCursorPos - This routine will position the cursor to an absolute */
  1597. X/*              screen coordinate using the BIOS video services.       */
  1598. X/*  Parms:                                   */
  1599. X/*    nRow        - Absolute screen row                   */
  1600. X/*    nCol        - Absolute screen column                   */
  1601. X/*                                       */
  1602. X/*  Return Value      None                           */
  1603. X/***************************************************************************/
  1604. X
  1605. void pascal ScrSetCursorPos(nRow, nCol)
  1606. short        nRow, nCol;
  1607. X{
  1608. X    auto     union REGS     r;
  1609. X
  1610. X    r.h.ah = BIOS_VID_SET_CURSORPOS;
  1611. X    r.h.dh = (BYTE) (nRow - 1);
  1612. X    r.h.dl = (BYTE) (nCol - 1);
  1613. X    r.h.bh = (BYTE) nCurrActivePage;
  1614. X    int86(BIOS_VID_INT, &r, &r);
  1615. X    return;
  1616. X}
  1617. X
  1618. X
  1619. X/***************************************************************************/
  1620. X/*  ScrGetCursorPos - This routine will return the current absolute       */
  1621. X/*              cursor position.                       */
  1622. X/*  Parms:                                   */
  1623. X/*    nRow        - Pointer to location to save current row           */
  1624. X/*    nCol        - Pointer to location to save current column       */
  1625. X/*                                       */
  1626. X/*  Return Value:     None                           */
  1627. X/***************************************************************************/
  1628. X
  1629. void pascal ScrGetCursorPos(nRow, nCol)
  1630. short        *nRow, *nCol;
  1631. X{
  1632. X    auto     union REGS     r;
  1633. X
  1634. X    r.h.ah = BIOS_VID_GET_CURSORPOS;
  1635. X    r.h.bh = (BYTE) nCurrActivePage;
  1636. X    int86(BIOS_VID_INT, &r, &r);
  1637. X    *nRow  = r.h.dh + 1;
  1638. X    *nCol  = r.h.dl + 1;
  1639. X    return;
  1640. X}
  1641. X
  1642. X
  1643. X/***************************************************************************/
  1644. X/*  ScrCusrosOn     - Enables the screen cursor.               */
  1645. X/*                                       */
  1646. X/*  Parms:          None                           */
  1647. X/*                                       */
  1648. X/*  Return Value:     None                           */
  1649. X/***************************************************************************/
  1650. X
  1651. void pascal ScrCursorOn()
  1652. X{
  1653. X    auto     union REGS     r;
  1654. X
  1655. X    r.h.ah = BIOS_VID_SET_CURSORTYPE;
  1656. X    r.x.cx = uCsrType;
  1657. X    int86(BIOS_VID_INT, &r, &r);
  1658. X    return;
  1659. X}
  1660. X
  1661. X
  1662. X/***************************************************************************/
  1663. X/*  ScrCusrosOff    - Disables the screen cursor.               */
  1664. X/*                                       */
  1665. X/*  Parms:          None                           */
  1666. X/*                                       */
  1667. X/*  Return Value:     None                           */
  1668. X/***************************************************************************/
  1669. X
  1670. void pascal ScrCursorOff()
  1671. X{
  1672. X    auto     union REGS     r;
  1673. X
  1674. X    r.h.ah = BIOS_VID_SET_CURSORTYPE;
  1675. X    r.x.cx = 0x0f00;
  1676. X    int86(BIOS_VID_INT, &r, &r);
  1677. X    return;
  1678. X}
  1679. X
  1680. X
  1681. X/***************************************************************************/
  1682. X/*  ScrTextOut - This function uses the BIOS write character and attribute */
  1683. X/*         service routine to display a string within a window.  The */
  1684. X/*         passed nCount is used to limit a string from overflowing  */
  1685. X/*         a window boundry.                       */
  1686. X/*  Parms:                                   */
  1687. X/*    pStr     - Pointer to the string to be displayed               */
  1688. X/*    nAttr    - Color attribute used to display string            */
  1689. X/*    nCount   - Maximum number of characters to dispalay           */
  1690. X/*                                       */
  1691. X/*  Return Value: None                               */
  1692. X/***************************************************************************/
  1693. X
  1694. void pascal ScrTextOut(pStr, nAttr, nCount)
  1695. register char    *pStr;
  1696. short         nAttr, nCount;
  1697. X{
  1698. X    register short        i;
  1699. X    auto     short        nRow, nCol;
  1700. X    auto     union REGS     r, r1;
  1701. X
  1702. X    ScrGetCursorPos(&nRow, &nCol);
  1703. X    nAttr  = ScrCvtAttr(nAttr);
  1704. X    r.h.ah = BIOS_VID_WRITE_CHATTR;
  1705. X    r.h.bh = (BYTE) nCurrActivePage;
  1706. X    r.h.bl = (BYTE) nAttr;
  1707. X    r.x.cx = 1;
  1708. X    while (*pStr && nCount-- > 0)
  1709. X    {
  1710. X    ScrSetCursorPos(nRow, nCol++);
  1711. X    r.h.al = *pStr++;
  1712. X    int86(BIOS_VID_INT, &r, &r1);
  1713. X    }
  1714. X    return;
  1715. X}
  1716. X
  1717. X
  1718. X/***************************************************************************/
  1719. X/*  ScrDrawRect - This routine is used to draw borders around a screen       */
  1720. X/*          window.  The passed parameters define the rectangle       */
  1721. X/*          being used by the window as well as the border color       */
  1722. X/*          and type.                           */
  1723. X/*  Parms:                                   */
  1724. X/*    nRow    - Top row of screen border                   */
  1725. X/*    nCol    - Left column of screen border                   */
  1726. X/*    nWidth    - Column width of the window                   */
  1727. X/*    nHeight    - Number of rows in the window                   */
  1728. X/*    nColor    - Color attribute for the window border            */
  1729. X/*    nType    - Type of border to be displayed               */
  1730. X/*                                       */
  1731. X/*  Return Value: None                               */
  1732. X/***************************************************************************/
  1733. X
  1734. void pascal ScrDrawRect(nRow, nCol, nWidth, nHeight, nColor, nType)
  1735. short        nRow, nCol, nWidth, nHeight, nColor, nType;
  1736. X{
  1737. X    register short       i;
  1738. X    auto     union REGS    r, r1;
  1739. X    static   BOXTYPE       BoxTypes[] =
  1740. X    {
  1741. X    {  32,    32,  32,  32,  32,  32,  32,  32 }, /* NO_BOX           */
  1742. X    { 213, 212, 184, 190, 179, 179, 205, 205 }, /* DBL_LINE_TOP_BOTTOM */
  1743. X    { 214, 211, 183, 189, 186, 186, 196, 196 }, /* DBL_LINE_SIDES       */
  1744. X    { 201, 200, 187, 188, 186, 186, 205, 205 }, /* DBL_LINE_ALL_SIDES  */
  1745. X    { 218, 192, 191, 217, 179, 179, 196, 196 }, /* SNGL_LINE_ALL_SIDES */
  1746. X    { 219, 219, 219, 219, 219, 219, 223, 220 }  /* GRAPHIC BOX     */
  1747. X    };
  1748. X
  1749. X    if (nType < 0 || nType >= MAXDIM(BoxTypes))
  1750. X    return;
  1751. X    if (nWidth < 2 || nHeight < 2)
  1752. X    return;
  1753. X    nColor = ScrCvtAttr(nColor);
  1754. X
  1755. X    /* Draw upper left corner */
  1756. X    ScrSetCursorPos(nRow, nCol);
  1757. X    r.h.ah = (BYTE) BIOS_VID_WRITE_CHATTR;
  1758. X    r.h.al = (BYTE) BoxTypes[nType].cUpperLeft;
  1759. X    r.h.bh = (BYTE) nCurrActivePage;
  1760. X    r.h.bl = (BYTE) nColor;
  1761. X    r.x.cx = 1;
  1762. X    int86(BIOS_VID_INT, &r, &r1);
  1763. X
  1764. X    /* Draw upper right corner */
  1765. X    ScrSetCursorPos(nRow, nCol + nWidth - 1);
  1766. X    r.h.al = (BYTE) BoxTypes[nType].cUpperRight;
  1767. X    int86(BIOS_VID_INT, &r, &r1);
  1768. X
  1769. X    /* Draw lower left corner */
  1770. X    ScrSetCursorPos(nRow + nHeight - 1, nCol);
  1771. X    r.h.al = (BYTE) BoxTypes[nType].cLowerLeft;
  1772. X    int86(BIOS_VID_INT, &r, &r1);
  1773. X
  1774. X    /* Draw lower right corner */
  1775. X    ScrSetCursorPos(nRow + nHeight - 1, nCol + nWidth - 1);
  1776. X    r.h.al = (BYTE) BoxTypes[nType].cLowerRight;
  1777. X    int86(BIOS_VID_INT, &r, &r1);
  1778. X
  1779. X    if (nHeight > 2)
  1780. X    {
  1781. X    /* Draw left side line */
  1782. X    r.h.al = (BYTE) BoxTypes[nType].cLeft;
  1783. X    for (i = 1; i <= nHeight - 2; ++i)
  1784. X    {
  1785. X        ScrSetCursorPos(nRow + i, nCol);
  1786. X        int86(BIOS_VID_INT, &r, &r1);
  1787. X    }
  1788. X
  1789. X    /* Draw right side line */
  1790. X    r.h.al = (BYTE) BoxTypes[nType].cRight;
  1791. X    for (i = 1; i <= nHeight - 2; ++i)
  1792. X    {
  1793. X        ScrSetCursorPos(nRow + i, nCol + nWidth - 1);
  1794. X        int86(BIOS_VID_INT, &r, &r1);
  1795. X    }
  1796. X    }
  1797. X
  1798. X    if (nWidth > 2)
  1799. X    {
  1800. X    /* Draw top line */
  1801. X    ScrSetCursorPos(nRow, nCol + 1);
  1802. X    r.h.al = (BYTE) BoxTypes[nType].cTop;
  1803. X    r.x.cx = nWidth - 2;
  1804. X    int86(BIOS_VID_INT, &r, &r1);
  1805. X
  1806. X    /* Draw bottom line */
  1807. X    ScrSetCursorPos(nRow + nHeight - 1, nCol + 1);
  1808. X    r.h.al = BoxTypes[nType].cBottom;
  1809. X    int86(BIOS_VID_INT, &r, &r1);
  1810. X    }
  1811. X
  1812. X    return;
  1813. X}
  1814. X
  1815. X
  1816. X/***************************************************************************/
  1817. X/*  ScrInitialize - Determine type of video card and init global data.       */
  1818. X/*                                       */
  1819. X/*  Parms:        None                           */
  1820. X/*                                       */
  1821. X/*  Return Value:   None                           */
  1822. X/***************************************************************************/
  1823. X
  1824. void pascal ScrInitialize()
  1825. X{
  1826. X    auto     union REGS     r;
  1827. X
  1828. X    r.h.ah = BIOS_VID_GET_CURSORPOS;
  1829. X    r.h.bh = (BYTE) nCurrActivePage;
  1830. X    int86(BIOS_VID_INT, &r, &r);
  1831. X    uCsrType = r.x.cx;
  1832. X
  1833. X    r.h.ah = BIOS_VID_GET_CRTMODE;
  1834. X    int86(BIOS_VID_INT, &r, &r);
  1835. X    nScrCols        = r.h.ah;
  1836. X    nCurrActivePage = r.h.bh;
  1837. X    if (7 == r.h.al)
  1838. X    {
  1839. X    uScrSeg    = 0xb000;
  1840. X    nVideoCard = VIDEO_MONO;
  1841. X    return;
  1842. X    }
  1843. X    r.h.ah = BIOS_VID_SET_CRTMODE;
  1844. X    r.h.al = 3;
  1845. X    int86(BIOS_VID_INT, &r, &r);
  1846. X    uScrSeg    = 0xb800;
  1847. X    nVideoCard = VIDEO_CGA;
  1848. X    return;
  1849. X}
  1850. END_OF_FILE
  1851. if test 19021 -ne `wc -c <'scrio.c'`; then
  1852.     echo shar: \"'scrio.c'\" unpacked with wrong size!
  1853. fi
  1854. chmod +x 'scrio.c'
  1855. # end of 'scrio.c'
  1856. fi
  1857. if test -f 'windemo.c' -a "${1}" != "-c" ; then 
  1858.   echo shar: Will not clobber existing file \"'windemo.c'\"
  1859. else
  1860. echo shar: Extracting \"'windemo.c'\" \(6095 characters\)
  1861. sed "s/^X//" >'windemo.c' <<'END_OF_FILE'
  1862. X
  1863. X#include <stdlib.h>
  1864. X#include <stddef.h>
  1865. X#include <time.h>
  1866. X#include <conio.h>
  1867. X#include "win.h"
  1868. X
  1869. X
  1870. static void Delay(nSeconds)
  1871. short       nSeconds;
  1872. X{
  1873. X    auto     time_t    lQuitTime;
  1874. X
  1875. X    time(&lQuitTime);
  1876. X    lQuitTime += (time_t) nSeconds;
  1877. X    while (time(NULL) < lQuitTime)
  1878. X    ;
  1879. X    return;
  1880. X}
  1881. X
  1882. X
  1883. X
  1884. static HWND IntroWindow()
  1885. X{
  1886. X    register HWND     hWnd;
  1887. X    auto     short     nTxtClr   = WHITE | REV_BLUE | HI_INTENSITY;
  1888. X    auto     short     nBriteClr = YELLOW | REV_BLUE | HI_INTENSITY;
  1889. X
  1890. X    hWnd = WinCreateWindow(7, 10, 60, 10, nTxtClr,
  1891. X               SNGL_LINE_ALL_SIDES, nTxtClr, TRUE);
  1892. X    WinCenterText(hWnd, 1, "Welcome to C-WIN", nTxtClr);
  1893. X    WinCenterText(hWnd, 3, "a public domain contribution by", nTxtClr);
  1894. X    WinCenterText(hWnd, 5, "Bob Withers", nBriteClr);
  1895. X    WinCenterText(hWnd, 6, "649 Meadowbrook St", nBriteClr);
  1896. X    WinCenterText(hWnd, 7, "Allen, Texas 75002", nBriteClr);
  1897. X    Delay(5);
  1898. X    WinMoveWindow(hWnd, 1, 10);
  1899. X    return(hWnd);
  1900. X}
  1901. X
  1902. X
  1903. static void DocWindow()
  1904. X{
  1905. X    register HWND     hWnd;
  1906. X    auto     short    nTxtClr = REV_WHITE | BLUE;
  1907. X
  1908. X    hWnd = WinCreateWindow(9, 10, 60, 16, nTxtClr,
  1909. X               DBL_LINE_ALL_SIDES, nTxtClr, FALSE);
  1910. X    WinCenterText(hWnd, 1, "C-WIN Version 1.00", nTxtClr);
  1911. X    WinSetCursorPos(hWnd, 3, 2);
  1912. X    WinTextOut(hWnd,
  1913. X           "C-WIN is a collection of simple windowing routines for",
  1914. X           nTxtClr);
  1915. X    WinSetCursorPos(hWnd, 4, 2);
  1916. X    WinTextOut(hWnd,
  1917. X           "the IBM/PC and true clones. The package was written with",
  1918. X           nTxtClr);
  1919. X    WinSetCursorPos(hWnd, 5, 2);
  1920. X    WinTextOut(hWnd,
  1921. X           "the Microsoft C Compiler V5.00 and has been tested under",
  1922. X           nTxtClr);
  1923. X    WinSetCursorPos(hWnd, 6, 2);
  1924. X    WinTextOut(hWnd,
  1925. X           "the Turbo-C as well as Quick-C compilers. In the past I",
  1926. X           nTxtClr);
  1927. X    WinSetCursorPos(hWnd, 7, 2);
  1928. X    WinTextOut(hWnd,
  1929. X           "have developed several windowing packages for the PC but",
  1930. X           nTxtClr);
  1931. X    WinSetCursorPos(hWnd, 8, 2);
  1932. X    WinTextOut(hWnd,
  1933. X           "always in assembly language. I wanted a package written",
  1934. X           nTxtClr);
  1935. X    WinSetCursorPos(hWnd, 9, 2);
  1936. X    WinTextOut(hWnd,
  1937. X           "in C to allow it to easily be ported to other compilers.",
  1938. X           nTxtClr);
  1939. X    WinSetCursorPos(hWnd, 10, 2);
  1940. X    WinTextOut(hWnd,
  1941. X           "C-WIN is the result of my first efforts at this goal.",
  1942. X           nTxtClr);
  1943. X    WinSetCursorPos(hWnd, 11, 2);
  1944. X    WinTextOut(hWnd,
  1945. X           "I'm releasing it to the public domain in the hopes that",
  1946. X           nTxtClr);
  1947. X    WinSetCursorPos(hWnd, 12, 2);
  1948. X    WinTextOut(hWnd,
  1949. X           "others may find it a suitable base for their own work.",
  1950. X           nTxtClr);
  1951. X    WinCenterText(hWnd, 14, "* Press any key to continue *",
  1952. X           REV_RED | WHITE | HI_INTENSITY);
  1953. X    getch();
  1954. X    WinDestroyWindow(hWnd);
  1955. X    return;
  1956. X}
  1957. X
  1958. X
  1959. static void ShowBorders()
  1960. X{
  1961. X    register short    i;
  1962. X    auto     short    nTxtClr = REV_WHITE | BLUE;
  1963. X    auto     HWND    hWnd[6];
  1964. X    static   char      *pText[] = {  "Windows can",
  1965. X                     "be drawn with",
  1966. X                     "various borders,",
  1967. X                     "or with",
  1968. X                     "no border",
  1969. X                     "at all!"
  1970. X                  };
  1971. X
  1972. X    for (i = 0; i < 6; ++i)
  1973. X    {
  1974. X    hWnd[i] = WinCreateWindow(2 + i * 2, 2 + i * 2, 30, 6,
  1975. X                  nTxtClr, i,
  1976. X                  REV_WHITE | i | HI_INTENSITY, TRUE);
  1977. X    WinCenterText(hWnd[i], 1, pText[i], nTxtClr);
  1978. X    Delay(1);
  1979. X    }
  1980. X    Delay(5);
  1981. X    for (i = 5; i >= 0; --i)
  1982. X    {
  1983. X    WinMoveWindow(hWnd[i], 2 + (5 - i) * 2, 50 - (5 - i) * 2);
  1984. X    Delay(1);
  1985. X    }
  1986. X    Delay(5);
  1987. X    for (i = 0; i < 6; ++i)
  1988. X    WinMoveWindow(hWnd[i], 2 + i * 2, 1);
  1989. X    Delay(5);
  1990. X    for (i = 5; i >= 0; --i)
  1991. X    WinDestroyWindow(hWnd[i]);
  1992. X    return;
  1993. X}
  1994. X
  1995. X
  1996. void HideShowWindow(hHideWnd)
  1997. HWND        hHideWnd;
  1998. X{
  1999. X    auto     HWND    hWnd;
  2000. X    auto     short   nTxtClr = REV_MAGENTA | BLUE | HI_INTENSITY;
  2001. X
  2002. X    hWnd = WinCreateWindow(1, 1, 30, 6, nTxtClr, NO_BOX, nTxtClr, FALSE);
  2003. X    WinCenterText(hWnd, 1, "Windows can be hidden", nTxtClr);
  2004. X    Delay(5);
  2005. X    WinHideWindow(hHideWnd);
  2006. X    WinCenterText(hWnd, 2, "Moved while hidden", nTxtClr);
  2007. X    Delay(2);
  2008. X    WinMoveWindow(hHideWnd, 7, 10);
  2009. X    WinCenterText(hWnd, 3, "and", nTxtClr);
  2010. X    WinCenterText(hWnd, 4, "re-shown at any time", nTxtClr);
  2011. X    Delay(5);
  2012. X    WinShowWindow(hHideWnd);
  2013. X    WinDestroyWindow(hWnd);
  2014. X    return;
  2015. X}
  2016. X
  2017. X
  2018. void ScrollWindow(hWnd)
  2019. register HWND     hWnd;
  2020. X{
  2021. X    auto     short     nRow, nCol;
  2022. X    auto     short     nWidth, nHeight;
  2023. X    auto     short     nWinClr;
  2024. X    auto     short     nNoRows;
  2025. X    auto     char     *pBuf;
  2026. X
  2027. X    nRow    = WinGetWindowRow(hWnd);
  2028. X    nCol    = WinGetWindowCol(hWnd);
  2029. X    nWidth  = WinGetWindowWidth(hWnd);
  2030. X    nHeight = nNoRows = WinGetWindowHeight(hWnd);
  2031. X    nWinClr = WinGetWindowClr(hWnd);
  2032. X    if (WinGetBorderType(hWnd) != NO_WIND_BORDER)
  2033. X    {
  2034. X    nWidth    += 2;
  2035. X    nHeight += 2;
  2036. X    }
  2037. X    pBuf = malloc(ScrGetRectSize(nWidth, nHeight));
  2038. X    if (NULL == pBuf)
  2039. X    return;
  2040. X    ScrSaveRect(nRow, nCol, nWidth, nHeight, pBuf);
  2041. X    WinScrollWindowUp(hWnd);
  2042. X    WinScrollWindowUp(hWnd);
  2043. X    WinCenterText(hWnd, nNoRows, "Windows can be scrolled up", nWinClr);
  2044. X    Delay(2);
  2045. X    WinScrollWindowUp(hWnd);
  2046. X    Delay(2);
  2047. X    WinScrollWindowUp(hWnd);
  2048. X    Delay(2);
  2049. X    WinScrollWindowDown(hWnd);
  2050. X    WinScrollWindowDown(hWnd);
  2051. X    WinCenterText(hWnd, 1, "Windows can be scrolled down", nWinClr);
  2052. X    Delay(2);
  2053. X    WinScrollWindowDown(hWnd);
  2054. X    Delay(2);
  2055. X    WinScrollWindowDown(hWnd);
  2056. X    Delay(2);
  2057. X    ScrRestoreRect(nRow, nCol, nWidth, nHeight, pBuf);
  2058. X    free(pBuf);
  2059. X    WinCenterText(hWnd, nNoRows, " Press any key to end demo ",
  2060. X          REV_RED | WHITE | HI_INTENSITY);
  2061. X    return;
  2062. X}
  2063. X
  2064. X
  2065. main()
  2066. X{
  2067. X    auto     HWND      hIntroWnd;
  2068. X
  2069. X    WinInitialize();
  2070. X    ScrCursorOff();
  2071. X    WinClearScreen(NULL, BLACK);
  2072. X    hIntroWnd = IntroWindow();
  2073. X    DocWindow();
  2074. X    WinMoveWindow(hIntroWnd, 16, 10);
  2075. X    ShowBorders();
  2076. X    HideShowWindow(hIntroWnd);
  2077. X    ScrollWindow(hIntroWnd);
  2078. X    getch();
  2079. X    WinDestroyWindow(hIntroWnd);
  2080. X    WinTerminate();
  2081. X    ScrCursorOn();
  2082. X    return(0);
  2083. X}
  2084. END_OF_FILE
  2085. if test 6095 -ne `wc -c <'windemo.c'`; then
  2086.     echo shar: \"'windemo.c'\" unpacked with wrong size!
  2087. fi
  2088. chmod +x 'windemo.c'
  2089. # end of 'windemo.c'
  2090. fi
  2091. echo shar: End of shell archive.
  2092. exit 0
  2093.  
  2094.